Makie

A data visualization ecosystem for Julia

Marie-Helene Burle
Wednesday, October 26

Plotting in Julia


Many options:

  • Plots.jl: high-level API for working with different back-ends (GR, Pyplot, Plotly…)
  • PyPlot.jl: Julia interface to Matplotlib’s matplotlib.pyplot
  • PlotlyJS.jl: Julia interface to plotly.js
  • PlotlyLight.jl: the fastest plotting option in Julia by far, but limited features
  • Gadfly.jl: following the grammar of graphics popularized by Hadley Wickham in R
  • VegaLite.jl: grammar of interactive graphics
  • PGFPlotsX.jl: Julia interface to the PGFPlots LaTeX package
  • UnicodePlots.jl: plots in the terminal 🙂
  • Makie.jl: powerful plotting ecosystem: animation, 3D, GPU optimization

Makie ecosystem

  • Main package:

    • Makie.jl: plots functionalities. Backend needed to render plots into images or vector graphics
  • Backends:

    • CairoMakie.jl: vector graphics or high-quality 2D plots (no true 3D). Creates, but does not display plots

    • GLMakie.jl: true 3D rendering and interactivity in GLFW window (no vector graphics)

    • WGLMakie.jl: web version of GLMakie (plots rendered in a browser instead of a window)

Syntax

Figure

Load the package
Here, we are using CairoMakie

using CairoMakie                        # no need to import Makie itself


Create a Figure (container object)

fig = Figure()



typeof(fig)
Figure

You can customize a Figure:

fig2 = Figure(backgroundcolor = :grey22, resolution=(300, 300))

Makie uses Colors.jl as a dependency
You can find a list of all named colours here

To use CSS specification (e.g. hex), you need to install Colors.jl explicitly and use its color parsing capabilities

using Colors
fig3 = Figure(backgroundcolor = colorant"#adc2eb")

Axis


Then, you can create an Axis

ax = Axis(Figure()[1, 1])
Axis with 1 plots:
 ┗━ Mesh{Tuple{GeometryBasics.Mesh{3, Float32, GeometryBasics.TriangleP{3, Float32, GeometryBasics.PointMeta{3, Float32, Point{3, Float32}, (:normals,), Tuple{Vec{3, Float32}}}}, GeometryBasics.FaceView{GeometryBasics.TriangleP{3, Float32, GeometryBasics.PointMeta{3, Float32, Point{3, Float32}, (:normals,), Tuple{Vec{3, Float32}}}}, GeometryBasics.PointMeta{3, Float32, Point{3, Float32}, (:normals,), Tuple{Vec{3, Float32}}}, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}, StructArrays.StructVector{GeometryBasics.PointMeta{3, Float32, Point{3, Float32}, (:normals,), Tuple{Vec{3, Float32}}}, NamedTuple{(:position, :normals), Tuple{Vector{Point{3, Float32}}, Vector{Vec{3, Float32}}}}, Int64}, Vector{GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}}}



typeof(ax)
Axis
Axis(fig3[1, 1])  # fig3[1, 1] sets the subplot layout: fig[row, col]
fig3
Axis(fig[2, 3])  # This is what happens if we change the layout
fig
Axis(fig3[2, 3])  # We can add another axis on fig3
fig3

Axis are customizable

fig4 = Figure()
Axis(fig4[1, 1],
     xlabel="x label",
     ylabel="y label",
     title="Title of the plot")
fig4

Plot

Finally, we can add a plot

fig = Figure()
ax = Axis(fig[1, 1])
x = LinRange(-10, 10, 20)
y = x
scatter!(ax, x, y)  # Functions with ! transform their arguments
fig

Of course, there are many plotting functions

fig = Figure()
ax = Axis(fig[1, 1])
x = LinRange(-10, 10, 20)
y = sin.(x)  # The . means that the function is broadcast to each element of x
lines!(ax, x, y)
fig

Let’s add points to get a smoother line

fig = Figure()
ax = Axis(fig[1, 1])
x = LinRange(-10, 10, 1000)
y = sin.(x)  # The . means that the function is broadcast to each element of x
lines!(ax, x, y)
fig

3D

Animations

Using the Alliance clusters

Questions?